package com.endurance.controller;

import com.endurance.vo.QueryVO;
import com.endurance.vo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class Test04JSONController {



    /**
     * 使用 @ResponseBody 把对象转换为JSON数据
     *
     * @return
     */
    @RequestMapping(value = "json1.do", method = RequestMethod.POST)
    public @ResponseBody User retUser() {
        return new User("小琳");
    }


    /**
     * 使用@RequestBody 注解把json数据转换为对象
     *
     * @param queryVO
     */
    @RequestMapping(value = "json2.do", method = RequestMethod.POST)
    public void acceptVariable(@RequestBody QueryVO queryVO) {
        System.out.println(queryVO.getName());
        System.out.println(queryVO.getAge());
        System.out.println(queryVO.getUser().getUsername());
    }

}
